################
#PSRM: Explaining Support for Redistribution: Social Insurance Systems and Fairness
#
#Observational Data
#Part IV: Unemployment Risk
#
#Verena Fetscher
#July 2022
####################


rm(list=ls())

##########################
#Load data
##########################

load("DataFile_04_Stability.Rda")


##########################
#Unemployment risk
##########################

#Import data

#Calculation unemployment risk
#Data Source Eurostat employment and unemployment
#website http://ec.europa.eu/eurostat/web/lfs/data/database
#Accessed 02-2017


#Previous occupations of the unemployed, by sex (1 000) (lfsq_ugpis)
#lfsa_ugpis_1_Data
#website http://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=lfsa_ugpis&lang=en 
UE_occu<-read.csv("lfsa_ugpis_1_Data.csv", header = TRUE, sep = ",", quote = "\"",
                  dec = ".")
names(UE_occu) <- c("TIME","GEO","SEX","ISCO08","UNIT","Value","Flag.and.Footnotes")

#Unemployment rates by sex, age and educational attainment level (%) (lfsq_urgaed)	 
#lfsa_urgaed_1_Data
#website http://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=lfsq_urgaed&lang=en
UE_rate<-read.csv("lfsa_urgaed_1_Data.csv", header = TRUE, sep = ",", quote = "\"",
                  dec = ".")
names(UE_rate) <- c("TIME","GEO","SEX","AGE","ISCED11","UNIT","Value","Flag.and.Footnotes")

#Employment by sex, occupation and educational attainment level (1 000)
#lfsa_egised_1_Data
#http://appsso.eurostat.ec.europa.eu/nui/show.do?dataset=lfsa_egised&lang=en
Empl<-read.csv("lfsa_egised_1_Data.csv", header = TRUE, sep = ",", quote = "\"",
               dec = ".")
names(Empl) <- c("TIME","GEO","SEX","ISCED11","ISCO08","UNIT","Value","Flag.and.Footnotes")

##########################
#Generate occupational unemployment rates
##########################

#Following Rehm (2011)
#unemployment rate of occupation j=
#unemployed in occupation j/(unemployed in occupation j + employed in occupation j)

#Generate main occupational groups based on ISCO main groups
table(Empl$ISCO08)

#iscoco: 	ESS1, ESS2, ESS3, ESS4, ESS5: What is/was the name or title 
#of your main job? In your main job, what kind of work do/did you do 
#most of the time? What training or qualifications are/were needed for the job?

table(na.omit(data$iscoco))
typeof(data$iscoco)
data$occupation<-NA
data$occupation[data$iscoco==100]<-"Armed forces occupations"
data$occupation[data$iscoco>100&data$iscoco<2000]<-"Managers"
data$occupation[data$iscoco>=2000&data$iscoco<3000]<-"Professionals"
data$occupation[data$iscoco>=3000&data$iscoco<4000]<-"Technicians and associate professionals"
data$occupation[data$iscoco>=4000&data$iscoco<5000]<-"Clerical support workers"
data$occupation[data$iscoco>=5000&data$iscoco<6000]<-"Service and sales workers"
data$occupation[data$iscoco>=6000&data$iscoco<7000]<-"Skilled agricultural, forestry and fishery workers"
data$occupation[data$iscoco>=7000&data$iscoco<8000]<-"Craft and related trades workers"
data$occupation[data$iscoco>=8000&data$iscoco<9000]<-"Plant and machine operators and assemblers"
data$occupation[data$iscoco>=9000&data$iscoco<=9330]<-"Elementary occupations"

length(na.omit(data$occupation))
table(data$occupation)

attributes(data$isco08)

#ESS6, ESS7: What is/was the name or title of your main job? 
#In your main job, what kind of work do/did you do most of the time? 
#What training or qualifications are/were needed for the job?
data$occupation[as.numeric(data$isco08)>=0&as.numeric(data$isco08)<8]<-"Armed forces occupations"
data$occupation[as.numeric(data$isco08)>=8&as.numeric(data$isco08)<52]<-"Managers"
data$occupation[as.numeric(data$isco08)>=52&as.numeric(data$isco08)<171]<-"Professionals"
data$occupation[as.numeric(data$isco08)>=171&as.numeric(data$isco08)<279]<-"Technicians and associate professionals"
data$occupation[as.numeric(data$isco08)>=279&as.numeric(data$isco08)<319]<-"Clerical support workers"
data$occupation[as.numeric(data$isco08)>=319&as.numeric(data$isco08)<375]<-"Service and sales workers"
data$occupation[as.numeric(data$isco08)>=375&as.numeric(data$isco08)<400]<-"Skilled agricultural, forestry and fishery workers"
data$occupation[as.numeric(data$isco08)>=400&as.numeric(data$isco08)<486]<-"Craft and related trades workers"
data$occupation[as.numeric(data$isco08)>=486&as.numeric(data$isco08)<542]<-"Plant and machine operators and assemblers"
data$occupation[as.numeric(data$isco08)>=542&as.numeric(data$isco08)<=591]<-"Elementary occupations"

table(data$occupation)
##########################


##########################
#Occupation Risk
##########################

table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE


##########################
#Add unemployment risk to ESS 
##########################
#By country and year


##########################
#Austria
##########################

country="Austria"
cntry<-"AT"
year=2002
round<-1


isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
                                                          , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
                                                          , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$unemployment)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)


#Change parameter values
isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
      , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
    , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE


##########################
#Belgium
##########################

country="Belgium"
cntry<-"BE"

year=2002
round<-1


isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"


Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

##########################
#Switzerland
##########################

country="Switzerland"
cntry<-"CH"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate

data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################

#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)


#Change parameter values
isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

##########################
#Germany
##########################

country="Germany (until 1990 former territory of the FRG)"
cntry<-"DE"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
####################################################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

##########################
#Denmark
##########################

country="Denmark"
cntry<-"DK"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################




#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

#By country
country="Spain"
cntry<-"ES"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################

#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

##########################
#Finland
##########################


country="Finland"
cntry<-"FI"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)


#Change parameter values
isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################

#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################

#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))


data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################




#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

#By country
country="France"
cntry<-"FR"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
#######################

####################################################
#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE



##########################
#GB
##########################


#By country
country="United Kingdom"
cntry<-"GB"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE



##########################
#Ireland
##########################

country="Ireland"
cntry<-"IE"

year=2002
round<-1

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE



##########################
#Italy
##########################

country="Italy"
cntry<-"IT"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))



data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE


##########################
#Netherlands
##########################

country="Netherlands"
cntry<-"NL"

year=2002
round<-1


isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE


##########################
#Norway
##########################

country="Norway"
cntry<-"NO"

year=2002
round<-1

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE

##########################
#Portugal
##########################

#By country
country="Portugal"
cntry<-"PT"

year=2002
round<-1

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################

#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################



#Occupation Risk
table(Empl$GEO)
#Austria,Belgium,Denmark,Finland,France,
#Germany (until 1990 former territory of the FRG),Ireland,
#Italy,Netherlands,Norway,Portugal,Spain,Sweden,Switzerland,United Kingdom

table(data$cntry)
#AT BE CH DE DK ES FI FR GB IE IT NL NO PT SE



##########################
#Sweden
##########################

country="Sweden"
cntry<-"SE"

year=2002
round<-1

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2004
round<-2

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2006
round<-3

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2008
round<-4

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2010
round<-5

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2012
round<-6

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))
UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Change year
year=2014
round<-7

isco<-"Armed forces occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Clerical support workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Craft and related trades workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Elementary occupations"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Managers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Plant and machine operators and assemblers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Service and sales workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Skilled agricultural, forestry and fishery workers"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)
##########################


isco<-"Technicians and associate professionals"

Empl.country<-as.numeric(gsub(",", "",as.character(
  factor(Empl$Value[Empl$GEO==country&Empl$TIME==year&Empl$ISCO08==isco][1]
         , exclude = 0))))

UE.country<-as.numeric(gsub(",", "",as.character(factor(
  UE_occu$Value[UE_occu$GEO==country&UE_occu$TIME==year&UE_occu$ISCO08==isco][1]
  , exclude = 0))))

data$risk[data$occupation==isco&data$cntry==cntry&data$essround==round]<-
  UE.country/(UE.country+Empl.country)

table(data$risk)
##########################


#Extract average unemployment rate
data$unemployment[data$cntry==cntry&data$essround==round]<-
  Empl.country<-as.numeric(gsub(",", "",as.character(
    factor(UE_rate$Value[UE_rate$GEO==country&UE_rate$TIME==year][1]
           , exclude = 0))))
##########################


#Mean unemployment risk by country
data%>%
  group_by(cntry,essround,occupation) %>%
  summarise(meanRisk = mean(risk,na.rm=T))


#Check
table(data$risk[data$occupation=="Technicians and associate professionals"&
                  data$cntry=="CH"&data$essround==4])


##########################
#Save data
##########################

save(data,file="DataFile_05_Risk.Rda")





